import time
from random import randint

from exceptiongroup import catch
from selenium import webdriver
from selenium.webdriver.common.by import By

from my_db import DbUtils


class WebTest:


    def login(self,user,pwd1,driver):
        # service = Service("chromedriver.exe")

        # driver = webdriver.Chrome(service=service)

        #  //*[@id="username"]
        name = user
        ele = driver.find_element(By.XPATH, '//input[@id="username"]')
        ele.send_keys(name)
        time.sleep(0.5)
        #  输入密码
        pwd = pwd1
        ele2 = driver.find_element(By.XPATH, '//input[@id="password"]')
        ele2.send_keys(pwd)

        # 点击登录
        ele3 = driver.find_element(By.XPATH, '//*[@id="login_btn"]')
        ele3.click()

        time.sleep(2)
        # #  获取实际结果
        # result = driver.find_element(By.XPATH, '//div[@id="logo"]/a').text
        # return result

    def register(self,name,pwd,rpwd,driver):
        name = name
        ele1 = driver.find_element(By.XPATH, '//input[@id="username"]')
        ele1.send_keys(name)

        pwd = pwd
        ele2 = driver.find_element(By.XPATH, '//input[@id="password"]')
        ele2.send_keys(pwd)

        rpwd = rpwd
        ele3 = driver.find_element(By.XPATH, '//input[@id="repassword"]')
        ele3.send_keys(rpwd)

        ele4 = driver.find_element(By.XPATH, '//*[@id="login_btn"]')
        ele4.click()
        time.sleep(2)

    def bankCard(self,cardBank1,cardId1,driver):
        cardBank = cardBank1
        cardId = cardId1

        ele00 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a')
        ele00.click()
        time.sleep(1)
        ele0 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a')
        ele0.click()
        time.sleep(1)
        ele1 = driver.find_element(By.XPATH, '//*[@id="bankCard_add_modal_btn"]')
        ele1.click()

        #
        # ele2 = driver.find_element(By.XPATH, '/html/body/div/div/aside/div[2]/nav/ul/li[4]/ul/li[3]/a')
        time.sleep(1)
        ele2 = driver.find_element(By.XPATH, '//input[@id="cardBank_add_input"]')
        ele2.send_keys(cardBank)

        ele3 = driver.find_element(By.XPATH, '//*[@id="bankCardAddModal"]/div/div/div[2]/form/div[2]/div[1]/div/label[1]/span')
        ele3.click()
        time.sleep(1)
        ele4 = driver.find_element(By.XPATH,'//*[@id="cardNum_add_input"]')
        ele4.send_keys(cardId)

        ele5 = driver.find_element(By.XPATH,'//*[@id="bankCard_save_btn"]')
        ele5.click()
        time.sleep(4)

    def deleCard(self,driver):
        ele00 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a')
        ele00.click()
        time.sleep(1)
        ele0 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a')
        ele0.click()
        time.sleep(1)

        ele1 = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[2]/div/div/div[1]/ul/li/button[2]')
        ele1.click()
        time.sleep(1)

        ele2 = driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[1]')
        ele2.click()
        time.sleep(4)

    def unDeleCard(self, driver):
        ele00 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a')
        ele00.click()
        time.sleep(1)
        ele0 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a')
        ele0.click()
        time.sleep(1)

        ele1 = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[2]/div/div/div[1]/ul/li/button[2]')
        ele1.click()
        time.sleep(1)

        ele2 = driver.find_element(By.XPATH, '/html/body/div[2]/div[2]/div/div/div/div/div/div/div/div[4]/button[2]')
        ele2.click()
        time.sleep(1)
    def BJCard(self, driver):
        ele00 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a')
        ele00.click()
        time.sleep(1)
        ele0 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a')
        ele0.click()
        time.sleep(1)

        ele1 = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[2]/div/div/div[1]/ul/li/button[1]')
        ele1.click()
        time.sleep(1)

        ele2 = driver.find_element(By.XPATH, '//*[@id="cardBank_update_input"]')
        ele2.send_keys("银行")
        time.sleep(0.5)

        ele3 = driver.find_element(By.XPATH, '//*[@id="bankCard_update_btn"]')
        ele3.click()
        time.sleep(3)

    def BJCardNub(self, driver):
        ele00 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a')
        ele00.click()
        time.sleep(1)
        ele0 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a')
        ele0.click()
        time.sleep(1)

        ele1 = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[2]/div/div/div[1]/ul/li/button[1]')
        ele1.click()
        time.sleep(1)

        ele2 = driver.find_element(By.XPATH, '//*[@id="cardNum_update_input"]')
        ele2.clear()
        for i in range(0,16):
            ele2.send_keys(randint(0,9))
        time.sleep(1)

        ele3 = driver.find_element(By.XPATH, '//*[@id="bankCard_update_btn"]')
        ele3.click()
        time.sleep(3)

    def FFBJCardNub(self, driver):
        ele00 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a')
        ele00.click()
        time.sleep(1)
        ele0 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a')
        ele0.click()
        time.sleep(1)

        ele1 = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[2]/div/div/div[1]/ul/li/button[1]')
        ele1.click()
        time.sleep(1)

        ele2 = driver.find_element(By.XPATH, '//*[@id="cardNum_update_input"]')
        ele2.clear()
        for i in range(0,17):
            ele2.send_keys(randint(0,9))
        time.sleep(1)

        ele3 = driver.find_element(By.XPATH, '//*[@id="bankCard_update_btn"]')
        ele3.click()
        time.sleep(3)

    def BJLBCardNub(self, driver):
        ele00 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/a')
        ele00.click()
        time.sleep(1)
        ele0 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[4]/ul/li[3]/a')
        ele0.click()
        time.sleep(1)

        ele1 = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div[2]/div/div/div[1]/ul/li/button[1]')
        ele1.click()
        time.sleep(1)

        ele2 = driver.find_element(By.XPATH, '//*[@id="bankCardUpdateModal"]/div/div/div[2]/form/div[2]/div[1]/div/label[2]/span')
        ele2.click()
        time.sleep(1)

        ele3 = driver.find_element(By.XPATH, '//*[@id="bankCard_update_btn"]')
        ele3.click()
        time.sleep(3)

    def BuyFund(self, driver):
        ele1 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a')
        ele1.click()
        time.sleep(1)

        ele2 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[1]/a')
        ele2.click()
        time.sleep(1)

        ele3 = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[6]/button')
        ele3.click()
        time.sleep(1)

        ele4 = driver.find_elements(By.XPATH, '//input[@id="password"]')[1]
        ele4.send_keys("666666")
        time.sleep(1)

        ele5 = driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]')
        ele5.click()
        time.sleep(3)
    def MisBuyFund(self, driver):
        ele1 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a')
        ele1.click()
        time.sleep(1)

        ele2 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[1]/a')
        ele2.click()
        time.sleep(1)

        ele3 = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[6]/button')
        ele3.click()
        time.sleep(1)

        ele4 = driver.find_elements(By.XPATH, '//input[@id="password"]')[1]
        ele4.send_keys("666667")
        time.sleep(1)

        ele5 = driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]')
        ele5.click()
        time.sleep(3)
    def BuyFundQX(self, driver):
        ele1 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a')
        ele1.click()
        time.sleep(1)

        ele2 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[2]/a')
        ele2.click()
        time.sleep(1)

        ele3 = driver.find_element(By.XPATH, '/html/body/div[1]/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[8]/button')
        ele3.click()
        time.sleep(1)

        ele4 = driver.find_elements(By.XPATH, '//input[@id="password"]')[1]
        ele4.send_keys("666666")
        time.sleep(1)

        ele5 = driver.find_element(By.XPATH, '/html/body/div[3]/div[3]/a[1]')
        ele5.click()
        time.sleep(3)

    def MisBuyFundQX(self, driver):
        ele1 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a')
        ele1.click()
        time.sleep(1)

        ele2 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[2]/a')
        ele2.click()
        time.sleep(1)

        ele3 = driver.find_element(By.XPATH,'/html/body/div[1]/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[8]/button')
        ele3.click()
        time.sleep(1)

        ele4 = driver.find_elements(By.XPATH, '//input[@id="password"]')[1]
        ele4.send_keys("666667")
        time.sleep(1)

        ele5 = driver.find_element(By.XPATH, '/html/body/div[3]/div[3]/a[1]')
        ele5.click()
        time.sleep(3)


    def BuyFundJJ(self, driver):
        ele1 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a')
        ele1.click()
        time.sleep(1)

        ele2 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[3]/a')
        ele2.click()
        time.sleep(1)

        ele3 = driver.find_element(By.XPATH, '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[9]/button')
        ele3.click()
        time.sleep(1)

        ele4 = driver.find_elements(By.XPATH, '//input[@id="password"]')[1]
        ele4.send_keys("666666")
        time.sleep(1)

        ele5 = driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]')
        ele5.click()
        time.sleep(3)
    def MisBuyFundJJ(self, driver):
        ele1 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/a')
        ele1.click()
        time.sleep(1)

        ele2 = driver.find_element(By.XPATH, '//*[@id="leftbaraside"]/div[2]/nav/ul/li[2]/ul/li[3]/a')
        ele2.click()
        time.sleep(1)

        ele3 = driver.find_element(By.XPATH,
                                   '/html/body/div/div/main/div/div/div/div/div[2]/div/table/tbody/tr[1]/td[9]/button')
        ele3.click()
        time.sleep(1)

        ele4 = driver.find_elements(By.XPATH, '//input[@id="password"]')[1]
        ele4.send_keys("666667")
        time.sleep(1)

        ele5 = driver.find_element(By.XPATH, '//*[@id="layui-layer1"]/div[3]/a[1]')
        ele5.click()
        time.sleep(3)




